/**********************************************************************************************************
** 驱动文件：	ups-YTR3330.c
** 驱动类型：	ups
** 设备名称：	科华UPS
** 设备型号：	YTR3330
** 设备品牌：	科华
** 设备协议：	Modbus-RTU
** 驱动描述：	适用于科华YTR33系列三进三出UPS
** 生成日期：	2020-08-21 18:49:16
**********************************************************************************************************/
#include "Includes.h"


/**********************************************************************************************************
* 定义设备数据点变量结构
**********************************************************************************************************/
typedef struct{
	Var BatteryStatus;							//电池性能状态
	Var BatteryRemainingTime;					//电池剩余供电时间
	Var BatteryCapacity;						//电池剩余容量
	Var BatteryTemperature;						//电池温度
	Var InputFreq;								//输入频率
	Var InputUA;								//输入A相电压
	Var InputUB;								//输入B相电压
	Var InputUC;								//输入C相电压
	Var InputIA;								//输入A相电流
	Var InputIB;								//输入B相电流
	Var InputIC;								//输入C相电流
	Var OutputMode;								//输出工作方式
	Var OutputFreq;								//输出频率
	Var OutputUA;								//输出A相电压
	Var OutputUB;								//输出B相电压
	Var OutputUC;								//输出C相电压
	Var OutputIA;								//输出A相电流
	Var OutputIB;								//输出B相电流
	Var OutputIC;								//输出C相电流
	Var OutputPA;								//输出A相有功功率
	Var OutputPB;								//输出B相有功功率
	Var OutputPC;								//输出C相有功功率
	Var OutputLoadRateA;						//输出A相负载率
	Var OutputLoadRateB;						//输出B相负载率
	Var OutputLoadRateC;						//输出C相负载率
	Var BypassFreq;								//旁路输入频率
	Var BypassUA;								//旁路A相电压
	Var BypassUB;								//旁路B相电压
	Var BypassUC;								//旁路C相电压
	Var BypassIA;								//旁路A相电流
	Var BypassIB;								//旁路B相电流
	Var BypassIC;								//旁路C相电流
	Var BypassPA;								//旁路A相有功功率
	Var BypassPB;								//旁路B相有功功率
	Var BypassPC;								//旁路C相有功功率
	Var SystemWorkStatus;					//系统工作状态
	Var RectifierWorkStatus;					//整流工作状态
	Var BatteryOperationStatus;					//电池运行状态
	Var OutputSA;								//输出A相视在功率
	Var OutputSB;								//输出B相视在功率
	Var OutputSC;								//输出C相视在功率
	Var BypassSA;								//旁路A相视功功率
	Var BypassSB;								//旁路B相视功功率
	Var BypassSC;								//旁路C相视功功率
	Var PositiveBatteryVoltage;					//正电池组电压
	Var NegativeBatteryVoltage;					//负电池组电压
	Var PositiveBatteryDischargeCurrent;		//正电池组放电电流
	Var NegativeBatteryDischargeCurrent;		//负电池组放电电流
	Var PositiveBatteryChargeCurrent;			//正电池组充电电流
	Var NegativeBatteryChargeCurrent;			//负电池组充电电流
	Var BatteryAbnormal;						//电池异常
	Var BatteryPowered;							//电池供电
	Var LowBattery;								//电池电量低
	Var DeadBattery;							//电池耗尽
	Var MainsAbnormal;							//市电异常
	Var AbnormalOutput;							//输出异常
	Var OverLoad;								//输出过载
	Var AbnormalBypass;							//旁路异常
	Var BypassSupply;							//旁路供电
	Var OnOffStatus;							//开关机状态
	Var BatteryTesting;							//电池测试中
	Var OtherUPSFaults;							//UPS其他故障
	Var MaintainBypassAirSwitchStatus;			//维护旁路空开状态
	Var EPO;									//EPO
	Var MainsVoltageStatus;						//市电电压状态
	Var MainsFrequencyStatus;					//市电频率状态
	Var MainsPhaseLoss;							//市电缺相
	Var UnbalancedMainsVoltage;					//市电电压不平衡
	Var MainsPhaseSequenceAbnormal;				//市电相序异常
	Var MainsPowerFailure;						//市电掉电
	Var BatteryOvervoltage;						//电池过压
	Var AbnormalBatteryCircuit;					//电池回路异常
	Var BatteryPolarityReversal;				//电池极性接反
	Var AbnormalBatteryTemperature;				//电池温度异常
	Var BypassVoltageStatus;					//旁路电压状态
	Var BypassFrequencyStatus;					//旁路频率状态
	Var BypassPhaseLoss;						//旁路缺相
	Var AbnormalBypassPhaseSequence;			//旁路相序异常
	Var BypassPowerFailure;						//旁路掉电
	Var BypassOverloadProtection;				//旁路过载保护
	Var InverterVoltageStatus;					//逆变电压状态
	Var InverterOverloadProtection;				//逆变过载保护
	Var AbnormalOutputCircuit;					//输出回路异常
	Var EcoFault;								//ECO故障
	Var MotherboardFailure;						//主板故障
	Var ParallelCommunicationFailure;			//并联通讯故障
	Var AbnormalParallelLine;					//并机线异常
}Data_Struct;									//定义变量结构


/**********************************************************************************************************
* 设备数据点变量属性声明
**********************************************************************************************************/
const static Var_Property_Def var_attr[] = {
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryStatus",
		"电池性能状态",
		"",
		"电池性能状态：1-电池物理链路异常；2-电池正常；3-电池低压告警；4-电池低压保护",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"BatteryRemainingTime",
		"电池剩余供电时间",
		"分钟",
		"电池剩余供电时间",
		0,
		0,
		"电池剩余供电时间充足",
		"电池剩余供电时间不足",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"BatteryCapacity",
		"电池剩余容量",
		"%",
		"电池剩余容量",
		0,
		0,
		"电池剩余容量过高",
		"电池剩余容量过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BatteryTemperature",
		"电池温度",
		"℃",
		"电池温度",
		0,
		0,
		"电池温度过高",
		"电池温度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"InputFreq",
		"输入频率",
		"Hz",
		"输入频率",
		0,
		0,
		"输入频率过高",
		"输入频率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"InputUA",
		"输入A相电压",
		"V",
		"输入A相电压",
		0,
		0,
		"输入A相电压过高",
		"输入A相电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"InputUB",
		"输入B相电压",
		"V",
		"输入B相电压",
		0,
		0,
		"输入B相电压过高",
		"输入B相电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"InputUC",
		"输入C相电压",
		"V",
		"输入C相电压",
		0,
		0,
		"输入C相电压过高",
		"输入C相电压过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"InputIA",
		"输入A相电流",
		"A",
		"输入A相电流",
		0,
		0,
		"输入A相电流过高",
		"输入A相电流过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"InputIB",
		"输入B相电流",
		"A",
		"输入B相电流",
		0,
		0,
		"输入B相电流过高",
		"输入B相电流过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"InputIC",
		"输入C相电流",
		"A",
		"输入C相电流",
		0,
		0,
		"输入C相电流过高",
		"输入C相电流过低",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OutputMode",
		"输出工作方式",
		"",
		"输出工作方式：1-其它；2-无输出；3-市电逆变；4-旁路；5-电池逆变；6-Booster；7-reducer",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputFreq",
		"输出频率",
		"Hz",
		"输出频率",
		0,
		0,
		"输出频率过高",
		"输出频率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputUA",
		"输出A相电压",
		"V",
		"输出A相电压",
		0,
		0,
		"输出A相电压过高",
		"输出A相电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputUB",
		"输出B相电压",
		"V",
		"输出B相电压",
		0,
		0,
		"输出B相电压过高",
		"输出B相电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputUC",
		"输出C相电压",
		"V",
		"输出C相电压",
		0,
		0,
		"输出C相电压过高",
		"输出C相电压过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"OutputIA",
		"输出A相电流",
		"A",
		"输出A相电流",
		0,
		0,
		"输出A相电流过高",
		"输出A相电流过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"OutputIB",
		"输出B相电流",
		"A",
		"输出B相电流",
		0,
		0,
		"输出B相电流过高",
		"输出B相电流过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"OutputIC",
		"输出C相电流",
		"A",
		"输出C相电流",
		0,
		0,
		"输出C相电流过高",
		"输出C相电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputPA",
		"输出A相有功功率",
		"KW",
		"输出A相有功功率",
		0,
		0,
		"输出A相有功功率过高",
		"输出A相有功功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputPB",
		"输出B相有功功率",
		"KW",
		"输出B相有功功率",
		0,
		0,
		"输出B相有功功率过高",
		"输出B相有功功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputPC",
		"输出C相有功功率",
		"KW",
		"输出C相有功功率",
		0,
		0,
		"输出C相有功功率过高",
		"输出C相有功功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputLoadRateA",
		"输出A相负载率",
		"%",
		"输出A相负载率",
		0,
		0,
		"输出A相负载率过高",
		"输出A相负载率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputLoadRateB",
		"输出B相负载率",
		"%",
		"输出B相负载率",
		0,
		0,
		"输出B相负载率过高",
		"输出B相负载率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputLoadRateC",
		"输出C相负载率",
		"%",
		"输出C相负载率",
		0,
		0,
		"输出C相负载率过高",
		"输出C相负载率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassFreq",
		"旁路输入频率",
		"Hz",
		"旁路输入频率",
		0,
		0,
		"旁路输入频率过高",
		"旁路输入频率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassUA",
		"旁路A相电压",
		"V",
		"旁路A相电压",
		0,
		0,
		"旁路A相电压过高",
		"旁路A相电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassUB",
		"旁路B相电压",
		"V",
		"旁路B相电压",
		0,
		0,
		"旁路B相电压过高",
		"旁路B相电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassUC",
		"旁路C相电压",
		"V",
		"旁路C相电压",
		0,
		0,
		"旁路C相电压过高",
		"旁路C相电压过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"BypassIA",
		"旁路A相电流",
		"A",
		"旁路A相电流",
		0,
		0,
		"旁路A相电流过高",
		"旁路A相电流过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"BypassIB",
		"旁路B相电流",
		"A",
		"旁路B相电流",
		0,
		0,
		"旁路C相电流过高",
		"旁路C相电流过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"BypassIC",
		"旁路C相电流",
		"A",
		"旁路C相电流",
		0,
		0,
		"旁路C相电流过高",
		"旁路C相电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassPA",
		"旁路A相有功功率",
		"KW",
		"旁路A相有功功率",
		0,
		0,
		"旁路A相有功功率过高",
		"旁路A相有功功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassPB",
		"旁路B相有功功率",
		"KW",
		"旁路B相有功功率",
		0,
		0,
		"旁路B相有功功率过高",
		"旁路B相有功功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassPC",
		"旁路C相有功功率",
		"KW",
		"旁路C相有功功率",
		0,
		0,
		"旁路C相有功功率过高",
		"旁路C相有功功率过低",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"SystemWorkStatus",
		"系统工作状态",
		"",
		"系统工作状态：0-初始化；1-故障保护；2-关机；3-并机切出；4-旁路；5-逆变；6-并网自动化；7-ECO模式；8-变频模式；9-维护旁路；10-并网自动化关机；11-变频模式关机；12-自动化旁路输出",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RectifierWorkStatus",
		"整流工作状态",
		"",
		"整流工作状态：0-启动中；1-故障； 2-市电升压；3-电池升压",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryOperationStatus",
		"电池运行状态",
		"",
		"电池运行状态：0-放电；1-均充；2-浮充；3-未知",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputSA",
		"输出A相视在功率",
		"KVA",
		"输出A相视在功率",
		0,
		0,
		"输出A相视在功率过高",
		"输出A相视在功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputSB",
		"输出B相视在功率",
		"KVA",
		"输出B相视在功率",
		0,
		0,
		"输出B相视在功率过高",
		"输出B相视在功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutputSC",
		"输出C相视在功率",
		"KVA",
		"输出C相视在功率",
		0,
		0,
		"输出C相视在功率过高",
		"输出C相视在功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassSA",
		"旁路A相视功功率",
		"KVA",
		"旁路A相视功功率",
		0,
		0,
		"旁路A相视功功率过高",
		"旁路A相视功功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassSB",
		"旁路B相视功功率",
		"KVA",
		"旁路B相视功功率",
		0,
		0,
		"旁路B相视功功率过高",
		"旁路B相视功功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassSC",
		"旁路C相视功功率",
		"KVA",
		"旁路C相视功功率",
		0,
		0,
		"旁路C相视功功率过高",
		"旁路C相视功功率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"PositiveBatteryVoltage",
		"正电池组电压",
		"V",
		"正电池组电压",
		0,
		0,
		"正电池组电压过高",
		"正电池组电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"NegativeBatteryVoltage",
		"负电池组电压",
		"V",
		"负电池组电压",
		0,
		0,
		"负电池组电压过高",
		"负电池组电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"PositiveBatteryDischargeCurrent",
		"正电池组放电电流",
		"A",
		"正电池组放电电流",
		0,
		0,
		"正电池组放电电流过高",
		"正电池组放电电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"NegativeBatteryDischargeCurrent",
		"负电池组放电电流",
		"A",
		"负电池组放电电流",
		0,
		0,
		"负电池组放电电流过高",
		"负电池组放电电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"PositiveBatteryChargeCurrent",
		"正电池组充电电流",
		"A",
		"正电池组充电电流",
		0,
		0,
		"正电池组充电电流过高",
		"正电池组充电电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"NegativeBatteryChargeCurrent",
		"负电池组充电电流",
		"A",
		"负电池组充电电流",
		0,
		0,
		"负电池组充电电流过高",
		"负电池组充电电流过低",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryAbnormal",
		"电池异常",
		"",
		"电池异常：0-正常；1-异常",
		0,
		0,
		"异常",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryPowered",
		"电池供电",
		"",
		"电池供电：0-无；1-电池供电",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"LowBattery",
		"电池电量低",
		"",
		"电池电量低：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"DeadBattery",
		"电池耗尽",
		"",
		"电池耗尽：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainsAbnormal",
		"市电异常",
		"",
		"市电异常：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AbnormalOutput",
		"输出异常",
		"",
		"输出异常：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OverLoad",
		"输出过载",
		"",
		"输出过载：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AbnormalBypass",
		"旁路异常",
		"",
		"旁路异常：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassSupply",
		"旁路供电",
		"",
		"旁路供电：0-非旁路；1-旁路输出",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OnOffStatus",
		"开关机状态",
		"",
		"开关机状态：0-关机；1-开机",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryTesting",
		"电池测试中",
		"",
		"电池测试中：0-无；1-测试中",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OtherUPSFaults",
		"UPS其他故障",
		"",
		"UPS其他故障：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MaintainBypassAirSwitchStatus",
		"维护旁路空开状态",
		"",
		"维护旁路空开状态：0-断开；1-闭合",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"EPO",
		"EPO",
		"",
		"EPO：0-关闭；1-开启",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainsVoltageStatus",
		"市电电压状态",
		"",
		"市电电压状态：0-正常；1-过压；2-欠压",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainsFrequencyStatus",
		"市电频率状态",
		"",
		"市电频率状态：0-正常；1-过频；2-欠频",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainsPhaseLoss",
		"市电缺相",
		"",
		"市电缺相：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"UnbalancedMainsVoltage",
		"市电电压不平衡",
		"",
		"市电电压不平衡：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainsPhaseSequenceAbnormal",
		"市电相序异常",
		"",
		"市电相序异常：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainsPowerFailure",
		"市电掉电",
		"",
		"市电掉电：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryOvervoltage",
		"电池过压",
		"",
		"电池过压：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AbnormalBatteryCircuit",
		"电池回路异常",
		"",
		"电池回路异常：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryPolarityReversal",
		"电池极性接反",
		"",
		"电池极性接反：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AbnormalBatteryTemperature",
		"电池温度异常",
		"",
		"电池温度异常：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassVoltageStatus",
		"旁路电压状态",
		"",
		"旁路电压状态：0-正常；1-过压；2-欠压",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassFrequencyStatus",
		"旁路频率状态",
		"",
		"旁路频率状态：0-正常；1-过频；2-欠频",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassPhaseLoss",
		"旁路缺相",
		"",
		"旁路缺相：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AbnormalBypassPhaseSequence",
		"旁路相序异常",
		"",
		"旁路相序异常：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassPowerFailure",
		"旁路掉电",
		"",
		"旁路掉电：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassOverloadProtection",
		"旁路过载保护",
		"",
		"旁路过载保护：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InverterVoltageStatus",
		"逆变电压状态",
		"",
		"逆变电压状态：0-正常；1-过压；2-欠压",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InverterOverloadProtection",
		"逆变过载保护",
		"",
		"逆变过载保护：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AbnormalOutputCircuit",
		"输出回路异常",
		"",
		"输出回路异常：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"EcoFault",
		"ECO故障",
		"",
		"ECO故障：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MotherboardFailure",
		"主板故障",
		"",
		"主板故障：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ParallelCommunicationFailure",
		"并联通讯故障",
		"",
		"并联通讯故障：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AbnormalParallelLine",
		"并机线异常",
		"",
		"并机线异常：0-正常；1-异常",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	}
};


/**********************************************************************************************************
* 函数名称： static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
* 函数说明： 生成获取传感器数据指令
* 输入参数： 指令索引，传感器地址，变量结构体指针,以及指令缓存区指针,指令长度
* 返回参数： 无
**********************************************************************************************************/
static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
{
	switch(index)
	{
		case 0:
			cmd[0] = addr;
			cmd[1] = 0x04;
			cmd[2] = 0x13;								
			cmd[3] = 0x88;
			cmd[4] = 0x00;	
			cmd[5] = 0x26;
			*len = CRC16_Padding(cmd, 6);
			break;
		case 1:
			cmd[0] = addr;
			cmd[1] = 0x04;
			cmd[2] = 0x14;								
			cmd[3] = 0x09;
			cmd[4] = 0x00;	
			cmd[5] = 0x10;
			*len = CRC16_Padding(cmd, 6);			
			break;
		case 2:
			cmd[0] = addr;
			cmd[1] = 0x02;
			cmd[2] = 0x13;								
			cmd[3] = 0x88;
			cmd[4] = 0x00;	
			cmd[5] = 0x10;
			*len = CRC16_Padding(cmd, 6);			
			break;
		case 3:
			cmd[0] = addr;
			cmd[1] = 0x02;
			cmd[2] = 0x13;								
			cmd[3] = 0xEC;
			cmd[4] = 0x00;
			cmd[5] = 0x38;
			*len = CRC16_Padding(cmd, 6);			
			break;			
		default:
			break;
	}
}


/**********************************************************************************************************
* 函数名称： static int parse_fun(short index, int addr, void *data, char *buf, short len)
* 函数说明： 解析传感器响应的数据，并写入数据库
* 输入参数： 解析索引,传感器地址，变量结构体指针，以及响应数据缓存取指针，响应数据长度
* 返回参数： 返回解析结果，返回0成功，返回1失败
**********************************************************************************************************/
static int parse_fun(short index, int addr, void *data, char *buf, short len)
{
	const char *BatteryStatus[] = {"未知","物理链路异常","正常","低压告警","低压保护"};
	const char *OutputMode[] = {"未知","其它","无输出","市电逆变","旁路","电池逆变","Booster","reducer"};
	const char *SystemWorkStatus[] = {"初始化","故障保护","关机","并机切出","旁路","逆变","并网自老化","ECO模式","变频模式","维护旁路","并网自老化关机","变频模式关机","自老化旁路输出"};
	const char *RectifierWorkStatus[] = {"启动中","故障","市电升压","电池升压"};
	const char *BatteryOperationStatus[] = {"放电","均充","浮充","未知"};
	
	union{
		unsigned short	dat16;
      	unsigned char  	dat8[2];
    }DAT16_8;						   //数据类型转换	
	Data_Struct	*d = (Data_Struct*)data;

	if(buf!=NULL && buf[0]==addr && len>0 )
	{	
		if(CRC16_Check(buf,len))
		{
			switch(index)
			{
				case 0:
					DAT16_8.dat8[1] = buf[3];
					DAT16_8.dat8[0] = buf[4];
					d->BatteryStatus.value.str = BatteryStatus[DAT16_8.dat16];
					DAT16_8.dat8[1] = buf[5];
					DAT16_8.dat8[0] = buf[6];
					d->BatteryRemainingTime.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[7];
					DAT16_8.dat8[0] = buf[8];
					d->BatteryCapacity.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[9];
					DAT16_8.dat8[0] = buf[10];
					d->BatteryTemperature.value.fnum = DAT16_8.dat16==0x8000?0:DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[13];
					DAT16_8.dat8[0] = buf[14];
					d->InputFreq.value.fnum = DAT16_8.dat16*0.01;
					DAT16_8.dat8[1] = buf[15];
					DAT16_8.dat8[0] = buf[16];
					d->InputUA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[17];
					DAT16_8.dat8[0] = buf[18];
					d->InputUB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[19];
					DAT16_8.dat8[0] = buf[20];
					d->InputUC.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[21];
					DAT16_8.dat8[0] = buf[22];
					d->InputIA.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[23];
					DAT16_8.dat8[0] = buf[24];
					d->InputIB.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[25];
					DAT16_8.dat8[0] = buf[26];
					d->InputIC.value.inum = DAT16_8.dat16;
					
					DAT16_8.dat8[1] = buf[27];
					DAT16_8.dat8[0] = buf[28];
					d->OutputMode.value.str = OutputMode[DAT16_8.dat16];					
					
					DAT16_8.dat8[1] = buf[31];
					DAT16_8.dat8[0] = buf[32];
					d->OutputFreq.value.fnum = DAT16_8.dat16*0.01;
					DAT16_8.dat8[1] = buf[33];
					DAT16_8.dat8[0] = buf[34];
					d->OutputUA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[35];
					DAT16_8.dat8[0] = buf[36];
					d->OutputUB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[37];
					DAT16_8.dat8[0] = buf[38];
					d->OutputUC.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[39];
					DAT16_8.dat8[0] = buf[40];
					d->OutputIA.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[41];
					DAT16_8.dat8[0] = buf[42];
					d->OutputIB.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[43];
					DAT16_8.dat8[0] = buf[44];
					d->OutputIC.value.inum = DAT16_8.dat16;
					
					DAT16_8.dat8[1] = buf[45];
					DAT16_8.dat8[0] = buf[46];
					d->OutputPA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[47];
					DAT16_8.dat8[0] = buf[48];
					d->OutputPB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[49];
					DAT16_8.dat8[0] = buf[50];
					d->OutputPC.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[51];
					DAT16_8.dat8[0] = buf[52];
					d->OutputLoadRateA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[53];
					DAT16_8.dat8[0] = buf[54];
					d->OutputLoadRateB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[55];
					DAT16_8.dat8[0] = buf[56];
					d->OutputLoadRateC.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[59];
					DAT16_8.dat8[0] = buf[60];
					d->BypassFreq.value.fnum = DAT16_8.dat16*0.01;
					DAT16_8.dat8[1] = buf[61];
					DAT16_8.dat8[0] = buf[62];
					d->BypassUA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[63];
					DAT16_8.dat8[0] = buf[64];
					d->BypassUB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[65];
					DAT16_8.dat8[0] = buf[66];
					d->BypassUC.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[67];
					DAT16_8.dat8[0] = buf[68];
					d->BypassIA.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[69];
					DAT16_8.dat8[0] = buf[70];
					d->BypassIB.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[71];
					DAT16_8.dat8[0] = buf[72];
					d->BypassIC.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[73];
					DAT16_8.dat8[0] = buf[74];
					d->BypassPA.value.fnum = DAT16_8.dat16*0.1;	
					DAT16_8.dat8[1] = buf[75];
					DAT16_8.dat8[0] = buf[76];
					d->BypassPB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[77];
					DAT16_8.dat8[0] = buf[78];
					d->BypassPC.value.fnum = DAT16_8.dat16*0.1;
					break;
				case 1:
					DAT16_8.dat8[1] = buf[3];
					DAT16_8.dat8[0] = buf[4];
					d->SystemWorkStatus.value.str = SystemWorkStatus[DAT16_8.dat16];
					DAT16_8.dat8[1] = buf[5];
					DAT16_8.dat8[0] = buf[6];
					d->RectifierWorkStatus.value.str = RectifierWorkStatus[DAT16_8.dat16];
					DAT16_8.dat8[1] = buf[7];
					DAT16_8.dat8[0] = buf[8];
					d->BatteryOperationStatus.value.str = BatteryOperationStatus[DAT16_8.dat16];

					DAT16_8.dat8[1] = buf[11];
					DAT16_8.dat8[0] = buf[12];
					d->OutputSA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[13];
					DAT16_8.dat8[0] = buf[14];
					d->OutputSB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[15];
					DAT16_8.dat8[0] = buf[16];
					d->OutputSC.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[17];
					DAT16_8.dat8[0] = buf[18];
					d->BypassSA.value.fnum = DAT16_8.dat16*0.1;		
					DAT16_8.dat8[1] = buf[19];
					DAT16_8.dat8[0] = buf[20];
					d->BypassSB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[21];
					DAT16_8.dat8[0] = buf[22];
					d->BypassSC.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[23];
					DAT16_8.dat8[0] = buf[24];
					d->PositiveBatteryVoltage.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[25];
					DAT16_8.dat8[0] = buf[26];
					d->NegativeBatteryVoltage.value.fnum = ((short)DAT16_8.dat16)*0.1;
					DAT16_8.dat8[1] = buf[27];
					DAT16_8.dat8[0] = buf[28];
					d->PositiveBatteryDischargeCurrent.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[29];
					DAT16_8.dat8[0] = buf[30];
					d->NegativeBatteryDischargeCurrent.value.inum = DAT16_8.dat16;
					DAT16_8.dat8[1] = buf[31];
					DAT16_8.dat8[0] = buf[32];
					d->PositiveBatteryChargeCurrent.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[33];
					DAT16_8.dat8[0] = buf[34];
					d->NegativeBatteryChargeCurrent.value.fnum = DAT16_8.dat16*0.1;
					break;
				case 2:
					SetStringDataPoint(&d->BatteryAbnormal,			buf[3]&0x01, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->BatteryPowered,			buf[3]&0x02, Alarm, Normal, "电池供电", "无");
					SetStringDataPoint(&d->LowBattery,				buf[3]&0x04, Alarm, Normal, "异常", "正常");					
					SetStringDataPoint(&d->DeadBattery,				buf[3]&0x08, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->MainsAbnormal,			buf[3]&0x10, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->AbnormalOutput,			buf[3]&0x20, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->OverLoad,				buf[3]&0x40, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->AbnormalBypass,			buf[3]&0x80, Alarm, Normal, "异常", "正常");
					
					SetStringDataPoint(&d->BypassSupply,			buf[4]&0x01, Alarm, Normal, "旁路输出", "非旁路");
					SetStringDataPoint(&d->OnOffStatus,			 	buf[4]&0x02, Normal, Alarm, "开机", "关机");
					SetStringDataPoint(&d->BatteryTesting,			buf[4]&0x04, Alarm, Normal, "测试中", "无");					
					SetStringDataPoint(&d->OtherUPSFaults,			buf[4]&0x08, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->MaintainBypassAirSwitchStatus,	buf[4]&0x20, Alarm, Normal, "闭合", "断开");
					SetStringDataPoint(&d->EPO,						buf[4]&0x40, Alarm, Normal, "开启", "正常");
					break;
				case 3:
					if(buf[3]&0x01){
						SetStringDataPoint(&d->MainsVoltageStatus,	1, Alarm, Normal, "过压", "正常");
					}
					else if(buf[3]&0x02){
						SetStringDataPoint(&d->MainsVoltageStatus,	1, Alarm, Normal, "欠压", "正常");
					}
					else{
						SetStringDataPoint(&d->MainsVoltageStatus,	0, Alarm, Normal, "报警", "正常");
					}
					if(buf[3]&0x04){
						SetStringDataPoint(&d->MainsFrequencyStatus,	1, Alarm, Normal, "过频", "正常");
					}
					else if(buf[3]&0x08){
						SetStringDataPoint(&d->MainsFrequencyStatus,	1, Alarm, Normal, "欠频", "正常");
					}
					else{
						SetStringDataPoint(&d->MainsFrequencyStatus,	0, Alarm, Normal, "报警", "正常");
					}
					SetStringDataPoint(&d->MainsPhaseLoss,				buf[3]&0x10, Alarm, Normal, "异常", "正常");					
					SetStringDataPoint(&d->UnbalancedMainsVoltage,		buf[3]&0x20, Alarm, Normal, "异常", "正常");					
					SetStringDataPoint(&d->MainsPhaseSequenceAbnormal,	buf[3]&0x40, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->MainsPowerFailure,			buf[3]&0x80, Alarm, Normal, "异常", "正常");

					SetStringDataPoint(&d->BatteryOvervoltage,			buf[5]&0x02, Alarm, Normal, "异常", "正常");					
					SetStringDataPoint(&d->AbnormalBatteryCircuit,		buf[5]&0x04, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->BatteryPolarityReversal,		buf[5]&0x08, Alarm, Normal, "异常", "正常");					
					SetStringDataPoint(&d->AbnormalBatteryTemperature,	buf[5]&0x10, Alarm, Normal, "异常", "正常");
					
					if(buf[7]&0x01){
						SetStringDataPoint(&d->BypassVoltageStatus,		1, Alarm, Normal, "过压", "正常");
					}
					else if(buf[7]&0x02){
						SetStringDataPoint(&d->BypassVoltageStatus,		1, Alarm, Normal, "欠压", "正常");
					}
					else{
						SetStringDataPoint(&d->BypassVoltageStatus,		0, Alarm, Normal, "报警", "正常");
					}
					if(buf[7]&0x04){
						SetStringDataPoint(&d->BypassFrequencyStatus,	1, Alarm, Normal, "过频", "正常");
					}
					else if(buf[7]&0x08){
						SetStringDataPoint(&d->BypassFrequencyStatus,	1, Alarm, Normal, "欠频", "正常");
					}
					else{
						SetStringDataPoint(&d->BypassFrequencyStatus,	0, Alarm, Normal, "报警", "正常");
					}
					SetStringDataPoint(&d->BypassPhaseLoss,				buf[7]&0x10, Alarm, Normal, "异常", "正常");					
					SetStringDataPoint(&d->AbnormalBypassPhaseSequence,	buf[7]&0x20, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->BypassPowerFailure,			buf[7]&0x40, Alarm, Normal, "异常", "正常");					
					SetStringDataPoint(&d->BypassOverloadProtection,	buf[7]&0x80, Alarm, Normal, "异常", "正常");
					
					if(buf[9]&0x01){
						SetStringDataPoint(&d->InverterVoltageStatus,	1, Alarm, Normal, "过压", "正常");
					}
					else if(buf[9]&0x02){
						SetStringDataPoint(&d->InverterVoltageStatus,	1, Alarm, Normal, "欠压", "正常");
					}
					else{
						SetStringDataPoint(&d->InverterVoltageStatus,	0, Alarm, Normal, "报警", "正常");
					}
					SetStringDataPoint(&d->InverterOverloadProtection,	buf[9]&0x04, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->AbnormalOutputCircuit,		buf[9]&0x08, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->EcoFault,					buf[9]&0x10, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->MotherboardFailure,			buf[9]&0x20, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->ParallelCommunicationFailure,buf[9]&0x40, Alarm, Normal, "异常", "正常");
					SetStringDataPoint(&d->AbnormalParallelLine,		buf[9]&0x80, Alarm, Normal, "异常", "正常");
					break;
				default:
					break;
			}
			return 0;
		}
	}
	return 1;
}


/**********************************************************************************************************
* 函数名称： void ups_YTR3330_Registration(void)
* 函数说明： 科华UPS驱动注册
* 输入参数： 无
* 返回参数： 无
**********************************************************************************************************/
void ups_YTR3330_Registration(void)
{
	DeviceDriverRegistration(
		"ups",													//设备类型
		"科华UPS",												//设备名称（导航栏默认显示名称）
		"科华",													//设备品牌
		"YTR3330",												//设备型号
		"适用于科华YTR33系列三进三出UPS",						//驱动描述
		var_attr,												//变量属性声明
		sizeof(Data_Struct),									//变量结构体空间大小
		cmd_fun,												//发送指令生成函数
		parse_fun,												//数据解析函数
		250														//设备响应超时时间
	);
#if 1 || VirtualFrameEN
	#define CMD1 "\x01\x04\x13\x88\x00\x26\xF5\x7E"
	#define RSP1 "\x01\x04\x4C\x00\x02\x03\xE7\x00\x64\x80\x00\x00\x03\x13\x84\x08\xC7\x08\xC4\x08\xC1\x00\x0C\x00\x0B\x00\x0B\x00\x03\x00\x03\x13\x85\x08\x95\x08\x95\x08\x96\x00\x0B\x00\x00\x00\x15\x00\x17\x00\x00\x00\x2F\x00\xF3\x00\x00\x01\xE5\x00\x03\x13\x85\x08\xC5\x08\xBC\x08\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x42"	
	#define CMD2 "\x01\x04\x14\x09\x00\x10\x24\x34"
	#define RSP2 "\x01\x04\x20\x00\x05\x00\x02\x00\x02\x00\x60\x00\x1B\x00\x00\x00\x31\x00\x00\x00\x00\x00\x00\x08\x83\xF7\x7F\x00\x00\x00\x00\x00\x00\x00\x00\x9A\x47"			
	#define CMD3 "\x01\x02\x13\x88\x00\x10\xFD\x68"
	#define RSP3 "\x01\x02\x02\x00\x12\x39\xB5"			
	#define CMD4 "\x01\x02\x13\xEC\x00\x38\xBC\xA9"
	#define RSP4 "\x01\x02\x07\x00\x00\x00\x00\x00\x00\x00\x79\x44"			
		
	VirtualFrameRegistration(CMD1, sizeof(CMD1)-1, RSP1, sizeof(RSP1)-1);
	VirtualFrameRegistration(CMD2, sizeof(CMD2)-1, RSP2, sizeof(RSP2)-1);
	VirtualFrameRegistration(CMD3, sizeof(CMD3)-1, RSP3, sizeof(RSP3)-1);
	VirtualFrameRegistration(CMD4, sizeof(CMD4)-1, RSP4, sizeof(RSP4)-1);	
#endif	
}

